Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip device placement for past key values in decoder models #23919

Merged
merged 1 commit into from
May 31, 2023

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented May 31, 2023

What does this PR do?

This PR skips the device placement for the past_key_values in big models, which is responsible for a lot of time lost according to the analysis in this issue. The idea is that the past key values (one per layer) are all generated on the device of the layer they correspond to and never need to be moved.

Needs to be tested with Accelerate at huggingface/accelerate#1491 (until this PR is merged).

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented May 31, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Should this be an array in case we want to skip several? It would make it more future-proof in case a model has such requirements over two variables

@sgugger
Copy link
Collaborator Author

sgugger commented May 31, 2023

Accelerate handles both strings and arrays :-)

@sgugger sgugger merged commit fabe17a into main May 31, 2023
@sgugger sgugger deleted the skip_keys_big_model branch May 31, 2023 19:32
@LysandreJik
Copy link
Member

thanks boss!

sheonhan pushed a commit to sheonhan/transformers that referenced this pull request Jun 1, 2023
gojiteji pushed a commit to gojiteji/transformers that referenced this pull request Jun 5, 2023
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants